<?php

/*
 *
 */

class Model_Mediate_ImportRecordDetail extends Model_BaseModel
{
    use Lib_BaseTraits;
    /**
     * 缓存前缀
     *
     * @var unknown
     */
    private static $tag = 'Model_Mediate_ImportRecordDetail';
    /**
     * Undocumented variable.
     *
     * @var string
     */
    private $table = 'import_record_detail';

    public function __construct()
    {
        // 选择连接的数据库
        parent::_init('mediation');
    }
    public function updateData($saveData, $where_data)
    {
        $saveArr =  $whereArr = $data = array();
        foreach ($saveData as $key => $value) {
            $temp = ':'.$key;
            $saveArr[] = '`'.$key.'`='.$temp;
            $data[$temp] = $value;
        }
        $i = 1;
        foreach ($where_data as $key => $value) {
            $temp = ':'.$key;
            if(in_array($temp,array_keys($data))){
                $temp = $temp.$i;
                $i ++;
            }
            $whereArr[] = '`'.$key.'`='.$temp;
            $data[$temp] = $value;
        }
        $sql = 'UPDATE `'.$this->table.'` SET '.implode(',', $saveArr).' WHERE '.implode(' and', $whereArr);
        //echo $sql;die();
        $res = $this->dao->conn(false)->noCache()->preparedSql($sql, $data)->affectedCount();
        $this->dao->clearTag(self::$tag);
        return $res;
    }
}
